package com._常用API;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.time.temporal.ChronoUnit;
import java.time.temporal.IsoFields;

/**
 * LocalDateTime LocalTime LocalDate 三个日期格式的 加减 格式化 获取年月日时分秒周
 * @author liyiruo
 * @Description
 * @Date 2024/7/15 下午5:05
 */
public class _LocalTime {

    public static void main(String[] args) {

        //年月日
        LocalDate date = LocalDate.now();
        System.out.println("date====>" + date);
        //时分秒
        LocalTime time = LocalTime.now();
        System.out.println("time======>" + time);
        //年月日时分秒
        LocalDateTime dateTime = LocalDateTime.now();
        System.out.println("dateTime========>" + dateTime);

        //加减 年月日时分秒
        dateTime = dateTime.plusYears(1);
        dateTime.plusMonths(1);
        dateTime.plusDays(1);
        dateTime.plusHours(1);
        dateTime.plusMinutes(1);
        dateTime.plusSeconds(1);
        dateTime.plusWeeks(1);

        dateTime.minusYears(2);
        dateTime.minusMonths(2);
        dateTime.minusDays(2);
        dateTime.minusHours(2);
        dateTime.minusMinutes(2);
        dateTime.minusSeconds(2);
        dateTime.minusWeeks(2);

        //比较
        dateTime.isAfter(dateTime);
        dateTime.isBefore(dateTime);
        dateTime.isEqual(dateTime);

        //检查一个Temporal对象是否支持某个字段
        dateTime.isSupported(IsoFields.QUARTER_YEARS);
        dateTime.isSupported(ChronoUnit.DAYS);
        dateTime.isSupported(ChronoUnit.MONTHS);
        

        //格式化
        DateTimeFormatter dateTimeformatter = DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss");
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy/MM/dd");
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss.SSS");
        String s_date = date.format(dateFormatter);
        String s_time = time.format(timeFormatter);
        String s_dateTime = dateTime.format(dateTimeformatter);
        System.out.println("格式化日期" + s_date);
        System.out.println("格式化时间" + s_time);
        System.out.println("格式化日期时间" + s_dateTime);


        //获取年月日
        int year = dateTime.getYear();
        int monthValue = dateTime.getMonthValue();
        int dayOfMonth = dateTime.getDayOfMonth();

        int dayOfYear = dateTime.getDayOfYear();
        int week = dateTime.getDayOfWeek().getValue();

        int year_f = dateTime.get(ChronoField.YEAR);
        int month = dateTime.get(ChronoField.MONTH_OF_YEAR);
        int day = dateTime.get(ChronoField.DAY_OF_MONTH);
        int day_Of_Year = dateTime.get(ChronoField.DAY_OF_YEAR);
        int week_f = dateTime.get(ChronoField.DAY_OF_WEEK);

        int hour = dateTime.get(ChronoField.HOUR_OF_DAY);

        System.out.println("year===========>" + year);
        System.out.println("monthValue===========>" + monthValue);
        System.out.println("dayOfMonth===========>" + dayOfMonth);

        System.out.println("dayOfYear===========>" + dayOfYear);
        System.out.println("week===========>" + week);


        System.out.println("year_f===========>" + year_f);
        System.out.println("month===========>" + month);
        System.out.println("day===========>" + day);
        System.out.println("day_Of_Year===========>" + day_Of_Year);
        System.out.println("week_f===========>" + week_f);

        System.out.println("hour===========>" + hour);


    }
}
